dtype_pos,ftype_pos,fname_pos,chr_pos,start_pos,stop_pos,strand_pos = 0,1,2,3,4,5,6

def distance(target_elems,feature_elems):
    
    if target_elems[chr_pos] == '' or feature_elems[chr_pos] == '':
        return 'NA'
    
    if target_elems[chr_pos] != feature_elems[chr_pos]:
        return 'NA'
    
    t1 = float(target_elems[start_pos])
    if target_elems[stop_pos] == '':
        t2 = t1
    else:
        t2 = float(target_elems[stop_pos])
        
    f1 = float(feature_elems[start_pos])
    if feature_elems[stop_pos] == '':
        f2 = f1
    else:
        f2 = float(feature_elems[stop_pos])
        
    return abs((t1+t2)/2 - (f1+f2)/2)
    
